package pers.lan.hash;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author <p><a href="mailto:1728209643@qq.com">XiaoSan</a>
 * @date 2019/9/16 9:04 AM
 */
public class LC_349 {

    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            set2.add(nums1[1]);
        }

        for (int i : nums2) {
            if (set2.contains(i)) {
                set.add(i);
            }
        }

        int[] res = new int[set.size()];
        Iterator iterator = set.iterator();
        int k = 0;
        while (iterator.hasNext()) {
            res[k] = (int) iterator.next();
            k++;
        }

        return res;
    }
}
